/**
 * Created by Administrator on 2015/6/4.
 */

var DB = require('./db');
var ObjectID = require('mongodb').ObjectID;


function Category() {

    this.name = '';

}

//查找分类
Category.list = function (type, callback) {

    var queryOption = {};
    if (type) {
        queryOption["type"] = type;
    }

    DB.connect(function (err, db) {
        if (err) {
            return callback(err, null);
        }

        var collection = db.collection('category');
        collection.find(queryOption).sort({"_id": -1}).toArray(function (err, docs) {
            db.close();

            return callback(err, docs);
        })
    })

}


module.exports = Category;
